package com.quanyan.user.web;

import com.quanyan.api.APIResponse;
import com.quanyan.api.enums.ApiResponseEnum;
import com.quanyan.user.service.HomePageService;
import com.quanyan.user.service.UserInformationService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * “我的”controller
 * Created by huadongyang on 2017/3/9.
 */
@RestController
@RequestMapping(value = "/api/user/my", method = RequestMethod.POST, produces = "application/json")
public class MyIndexController {
    private static final Logger logger = LoggerFactory.getLogger(MyIndexController.class);

    @Autowired
    private HomePageService homePageService;

    @Autowired
    private UserInformationService userInformationService;

    @RequestMapping("/myIndex")
    public APIResponse getMyIndex(HttpServletRequest request){
        Integer uid = (Integer) request.getAttribute("uid");
        if (uid == null ) {
            return APIResponse.returnFail(ApiResponseEnum.COOKIES_IS_NULL);
        }
        return homePageService.getMyIndex(uid);
    }

    @RequestMapping("index")
    public APIResponse myIndex(HttpServletRequest request){
        Integer uid = (Integer) request.getAttribute("uid");
        if (uid == null || uid <= 0 ) {
            return APIResponse.returnFail(ApiResponseEnum.COOKIES_IS_NULL);
        }
        return homePageService.getMyIndexInfo(uid);
    }

}
